package com.tanhua.server.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import com.tanhua.dubbo.server.api.RecommendUserApi;
import com.tanhua.dubbo.server.pojo.RecommendUser;
import com.tanhua.dubbo.server.vo.PageInfo;
import com.tanhua.server.service.RecommendUserService;
import com.tanhua.server.vo.TodayBest;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RecommendUserServiceImpl implements RecommendUserService {
    @Reference(version = "1.0.0")
    private RecommendUserApi recommendUserApi;


    @Override
    public TodayBest queryTodayBest(Long userId) {
        RecommendUser recommendUser = this.recommendUserApi.queryWithMaxScore(userId);
        if(null==recommendUser){
            return null;
        }
        TodayBest todayBest=new TodayBest();
        todayBest.setId(recommendUser.getUserId());
        //缘分
        double fateValue = Math.floor(recommendUser.getScore());
        todayBest.setFateValue(Double.valueOf(fateValue).longValue());
        return todayBest;
    }

    @Override
    public PageInfo<RecommendUser> queryRecommendation(Long toUserId, Integer page, Integer pageSize) {
        PageInfo<RecommendUser> recommendUserPageInfo = this.recommendUserApi.queryPageInfo(toUserId, page, pageSize);

        return recommendUserPageInfo;
    }

    @Override
    public Double queryScore(Long userId, Long toUserId) {
        Double score= this.recommendUserApi.queryScore(userId, toUserId);
        if(ObjectUtil.isNotEmpty(score)){
            return score;
        }
        return 98d;
    }

    @Override
    public List<RecommendUser> queryCardList(Long UserId,int count) {

        return this.recommendUserApi.queryCardList(UserId,count);
    }
}
